package com.card.hwatt.assembler;

import java.util.ArrayList;
import java.util.List;

import com.card.hwatt.core.ObjectUtil;
import com.card.hwatt.dto.PageResult;
import com.card.hwatt.entity.*;

/**
 * 考勤
 * @author Administrator
 *
 */
public final class CardAssembler {

	public static PageResult<com.card.hwatt.dto.Card> convert(
			PageResult<Card> list) {
		PageResult<com.card.hwatt.dto.Card> result = new PageResult<com.card.hwatt.dto.Card>();
		result.rows = new ArrayList<com.card.hwatt.dto.Card>();
		result.total = list.total;
		for (Card item : list.rows) {
			com.card.hwatt.dto.Card dto = convert(item);
			result.rows.add(dto);
		}
		return result;
	}

	/**
	 * 数据转换
	 */
	public static List<com.card.hwatt.dto.Card> convert(List<Card> list) {
		List<com.card.hwatt.dto.Card> rows = new ArrayList<com.card.hwatt.dto.Card>();
		for (Card item : list) {
			com.card.hwatt.dto.Card dto = convert(item);
			rows.add(dto);
		}
		return rows;
	}

	/**
	 * 数据转换
	 */
	public static com.card.hwatt.dto.Card convert(Card entity) {
		com.card.hwatt.dto.Card dto = new com.card.hwatt.dto.Card();
		ObjectUtil.fieldCopy(entity, dto);

		dto.employeeId = entity.employee.id;
		dto.employeeCode = entity.employee.employeeCode;
		dto.employeeName = entity.employee.name;
		dto.departmentName = entity.employee.department.name;
		dto.departmentId = entity.employee.department.id;
		return dto;
	}

	/**
	 * 数据转换
	 */
	public static Card convert(com.card.hwatt.dto.Card dto) {
		Card entity = new Card();
		ObjectUtil.fieldCopy(dto, entity);

		entity.employee = new Employee();
		entity.employee.id = dto.employeeId;

		return entity;
	}
}
